<?php
include_once (SYSTEM.'/Pattern.php');
include_once (SYSTEM.'/Route.php');
class Routes
{
	private $patterns;
	
	public function __construct()
	{
		$this->patterns = array();
	}

	public function AddRoutes($pattern)
	{
		$this->patterns[$pattern->NumberPart][] = $pattern;
	}

	public function MatchRoute($url)
	{			
		rtrim($url, '/');		
				
		$partsOfUrl = explode('/', $url);
		$numberPart = count($partsOfUrl);
		
		$listPatterns = $this->patterns[$numberPart];	
		
		$route = null;
		
		foreach ($listPatterns as $pt)
		{
			$route = $pt->ValidateUrlPattern($partsOfUrl);
			if($route != null)
			{
				break;
			}
		}
				
		return $route;
	}
}
